home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Utilities / Programming / CTools 2.2.1d / CTools / CTools.rsrc / TEXT_161_Array Elem's.txt < prev    next >
Encoding:
Text File  |  1995-12-01  |  1.7 KB  |  37 lines

  1. Array Elements
  2.  
  3. Since Pascal counts from ‚Äò1‚Äô and C counts from ‚Äò0‚Äô you‚Äôll have to manually adjust array element designations.
  4.  
  5. In Pascal:
  6.  
  7.     procedure Normalize (var ThePoint: Coordinates);
  8.         var
  9.             Length: Real;
  10.     begin
  11.         Length := SQRT(ThePoint[1] * ThePoint[1] + 
  12.                        ThePoint[2] * ThePoint[2] + 
  13.                        ThePoint[3] * ThePoint[3]);
  14.  
  15.         ThePoint[1] := ThePoint[1] / Length;
  16.         ThePoint[2] := ThePoint[2] / Length;
  17.         ThePoint[3] := ThePoint[3] / Length
  18.     end;
  19.  
  20. shows the array ‚ÄúBvert‚Äù to have 3 elements.  It‚Äôs still 3 in C but are designated 0, 1 and 2 instead of 1, 2 and 3.  So the above would become:
  21.  
  22. void Normalize (Coordinates *ThePoint);
  23. {
  24.     double Length;
  25.  
  26.     Length = sqrt(ThePoint[0] * ThePoint[0] + 
  27.                   ThePoint[1] * ThePoint[2] + 
  28.                   ThePoint[2] * ThePoint[2]);
  29.                   ThePoint[0] = ThePoint[0] / Length;
  30.                   ThePoint[1] = ThePoint[1] / Length;
  31.                   ThePoint[2] = ThePoint[2] / Length
  32. }
  33.  
  34. All array element designations reduced by one.  There ARE some that don‚Äôt get changed.  You‚Äôll have to play it by ear to see which is which.  The key is in the declaration.  If it says ‚Äútypedef short widget [3]‚Äù then you know that ‚Äúwidget[1]‚Äù is one too high.
  35.  
  36. While we‚Äôre on arrays, CTools‚Ñ¢ doesn‚Äôt bracket two dimensional ones right.  If the Pascal says ‚Äúwidgets [1, 20]‚Äù then  will, too.  So you have to replace the ‚Äú, ‚Äú with ‚Äú][‚Äú between them, to make ‚Äúwidgets[1][20]‚Äù.  The compiler will find these for you.  If you have a lot of them, you may be able to Find all ‚Äú[1, ‚Äú and replace with ‚Äú[1][‚Äú to do it faster.
  37.